package com.ocom.payhandle.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.card.EntityXfGoodsListProcess;
import com.ocom.common.vo.payconfig.kitchenprinter.GoodsListProcessDishesDto;
import com.ocom.common.vo.pyhandle.OrderMealListVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface IDaoXfGoodsListProcess extends BaseMapper<EntityXfGoodsListProcess> {

    @Select({"<script>",
            "SELECT\n" +
                    "G.dishes_id,\n" +
                    "G.dishes_price,\n" +
                    "G.unit_price,\n" +
                    "G.weight_number,\n" +
                    "D.dishes_class_id,\n" +
                    "G.dishes_name,\n" +
                    "C.dishes_class_name\n" +
                    "FROM\n" +
                    "xf_goods_list_process G\n" +
                    "LEFT JOIN dishes_info D ON D.dishes_id = G.dishes_id\n" +
                    "LEFT JOIN dishes_class C ON C.dishes_class_id = D.dishes_class_id\n" +
                    "WHERE\n" +
                    "G.com_id = #{comId}\n" +
                    "AND G.order_no = #{orderNo}\n" +
                    "ORDER BY\n" +
                    "D.dishes_class_id",
            "</script>"})
    List<GoodsListProcessDishesDto> getGoodsListProcessOnDishes(@Param("comId")Long comId, @Param("orderNo") String orderNo);



    @Select({"<script>",
            "select  N.point_id ,R.meal_no, R.dishes_id , N.receipt_id , N.receipt_name , P.point_name , \n" +
                    "D.dishes_name as menuName , D.dishes_code as menuCode,D.photo_url  \n" +
                    "from xf_goods_list_process as R   \n" +
                    "left join xf_record_process as N on N.order_no = R.order_no \n" +
                    "left join dishes_info as D on R.dishes_id = D.dishes_id \n" +
                    "left join xf_point_info as P on P.point_id = R.point_id \n" +
                    "where R.com_id = #{comId} and R.p_id = #{pId} and R.if_refund = 0 \n" +
                    "and R.meal_date= #{mealDate} " +
                    " <when test=\"mealNo !=null and  mealNo >0 \" > "+
                    "and  R. meal_no= #{mealNo}  \n" +
                    " </when> "+
                    "and  N.cons_state = 5  \n" +
                    "order by R.point_id , R.dishes_id  ",
            "</script>"})
    List<OrderMealListVo> getOrderListByMeal(@Param("comId")Long comId,
                                             @Param("pId") Long pId,
                                             @Param("mealDate") String mealDate,
                                             @Param("mealNo") Integer mealNo
                                             );

}
